package com.example.demo.blog;

import com.example.demo.mapper.ArticleMapper;
import com.example.demo.model.Article;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 豆腐干Sama on 2018/3/2.
 */
@Service
public class ArticleService {
    @Autowired
    private ArticleMapper mapper;
    public PageInfo<Article> articles(int pageNo) {
        PageHelper.offsetPage((pageNo-1)*10,10);
        List<Article> result = mapper.getAll();
        PageInfo<Article> pageInfo = new PageInfo<>(result);
        return pageInfo;
    }
    public Article get(int id) {
        Article article = mapper.selectByPrimaryKey(id);
        return article;
    }

    public void insert(Article article) {
        mapper.insertSelective(article);
    }
}
